package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.itheima.health.mapper.ReportMapper;
import com.itheima.health.pojo.Member;
import com.itheima.health.service.MemberService;
import com.itheima.health.service.ReportService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class ReportServiceImpl   implements ReportService {

    @Autowired
    ReportMapper reportMapper;
    @Override
    public Map findMemberLastYear() {
        List<Map> listMap =  reportMapper.findMemberLastYear();
        Map map = changeToMap(listMap);
        return map;
    }

    @Override
    public List<Map> findSetmealProportion() {
        return reportMapper.findSetmealProportion();
    }

    /**
     * 数据的转换实现
     * @param listMap
     * @return
     */
    private Map changeToMap(List<Map> listMap) {
        Map map = new HashMap();
        List totalCounts = new ArrayList();
        List  yearAndMonths = new ArrayList();
        for (Map map1 : listMap) {
            totalCounts.add(map1.get("totalCounts"));
            yearAndMonths.add(map1.get("yearAndMonth"));
        }
        map.put("totalCounts",totalCounts);
        map.put("yearAndMonths",yearAndMonths);
        return map;
    }
}
